import {Component, OnInit, Output, EventEmitter, DoCheck, Input} from '@angular/core';
import {Farm} from '../../../../entity/farm.model';
import {Http} from '@angular/http';
import {Observable} from 'rxjs/Rx';

@Component({
  selector: 'app-farm-multi-selector',
  templateUrl: './farm-multi-selector.component.html',
  styleUrls: ['./farm-multi-selector.component.css']
})
export class FarmMultiSelectorComponent implements OnInit {

  /**
   * 选中项发生改变
   *
   *
   * @memberof FarmSelectorComponent
   */
  @Output() public selectedChange: EventEmitter<ChangeArgs> = new EventEmitter<ChangeArgs>();

  /**
   * 风场集合
   *
   * @type {Farm[]}
   * @memberof FarmSelectorComponent
   */
  @Input() public farms: Farm[] = [];

  /**
   * 变化参数
   *
   * @private
   * @type {ChangeArgs}
   * @memberof FarmMultiSelectorComponent
   */
  private changeArgs: ChangeArgs = {
    unSelected: [],
    selected: []
  };

  constructor() {
  }

  ngOnInit() {

  }

  onCheack(event: HTMLInputElement, currfarm: Farm) {
    this.changeArgs.selected = [];
    this.changeArgs.unSelected = [];

    if (event.checked && event.checked == true) {
      this.changeArgs.selected.push(currfarm);
    }
    else {
      this.changeArgs.unSelected.push(currfarm);
    }

    this.farms.forEach(farm => {
      if (farm.farmId != currfarm.farmId) {
        if (farm.isChecked && farm.isChecked == true) {
          this.changeArgs.selected.push(farm);
        }
        else {
          this.changeArgs.unSelected.push(farm);
        }
      }
    });
    this.selectedChange.emit(this.changeArgs);
  }

}

export interface ChangeArgs {
  /**
   * 移除的风场
   *
   * @type {Farm[]}
   * @memberof ChangeArgs
   */
  unSelected: Farm[];


  /**
   * 选中的风场
   *
   * @type {Farm[]}
   * @memberof ChangeArgs
   */
  selected: Farm[];
}


// WEBPACK FOOTER //
// ./src/app/module/monitor/turbine-matrix/farm-multi-selector/farm-multi-selector.component.ts
